/*
NinjaTrader Strategy of Strategy 1.8
Generated by StrategyQuant version 3.6.3
Generated at Sat Sep 06 21:09:00 GMT 2014
Tested on EURUSD_fhdb, D1, 01.11.2007 - 29.03.2013
Spread: 2.5, Slippage: 0.0, Min distance of stop from price: 5.0
*/
#region Using declarations
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Indicator;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Strategy;
#endregion
namespace NinjaTrader.Strategy
{
///
/// Enter the description of your strategy here
///
[Description("Enter the description of your strategy here")]
public class Strategy18 : SQManagedStrategy
{
#region Variables
// Wizard generated variables
// User defined variables (add any user defined variables below)
#endregion
///
/// This method is used to configure the strategy and is called once before any strategy method is called.
///
protected override void Initialize()
{
base.Initialize();
ReplacePendingOrders = true;
ExitOnClose = false;
MinimumPTSL = 30;
MaximumPTSL = 300;
PendingOrderValidOneBar = false;
BarsRequired = 120;
StrictStopPrices = true;
LimitSignalsToRange = false;
TimeRangeFrom = 0800;
TimeRangeTo = 1600;
MaxTradesPerDay = 0; // 0 means unlimited
}
///
/// Called on each bar update event (incoming tick)
///
protected override void OnBarUpdate()
{
// ------------------------------------------
// STRATEGY MANAGEMENT
// ------------------------------------------
if(Bars.FirstBarOfSession) tradesPerDay = 0;
// Stop/Limit order expiration handling
// Long --------
if(pendingEntryOrder != null && pendingEntryOrder.OrderAction == OrderAction.Buy) {
// Expiration
if(sqGetPendingOrderBars(pendingEntryOrder) >= 39) {
CancelOrder(pendingEntryOrder);
}
}
// Short --------
if(pendingEntryOrder != null && pendingEntryOrder.OrderAction == OrderAction.SellShort) {
// Expiration
if(sqGetPendingOrderBars(pendingEntryOrder) >= 39) {
CancelOrder(pendingEntryOrder);
}
}
// ------------------------------------------
// ENTRY RULES
// ------------------------------------------
tradeEntered = false;
if(sqCheckTimeWithinRange()) {
// Long --------
if(maxTradesPerDay == 0 || tradesPerDay < maxTradesPerDay) {
bool LongEntryCondition = sqStoch(40, 1, 3, 0) > 50;
if(LongEntryCondition == true) {
double price = roundPrice(HeikenAshi().HAClose[0+0] + (0.2) * (Math.Abs(LinReg(95)[0] - High[11])));
sqEnterLongStop(price);
}
}
// Short --------
if(maxTradesPerDay == 0 || tradesPerDay < maxTradesPerDay) {
bool ShortEntryCondition = sqStoch(40, 1, 3, 0) < 50;
if(ShortEntryCondition == true) {
double price = roundPrice(HeikenAshi().HAClose[0+0] + (-0.2) * (Math.Abs(LinReg(95)[0] - Low[11])));
sqEnterShortStop(price);
}
}
}
// ------------------------------------------
// MANAGE TRADE & EXIT RULES
// ------------------------------------------
if(tradeEntered) {
// don't modify SL is new order was just placed
return;
}
IOrder slOrder = sqGetStopLossOrder();
double priceLevel;
// Long --------
// Exit After X Bars
if(Position.MarketPosition == MarketPosition.Long) {
if (BarsSinceEntry("Long") >= 5-1) {
sqExitLong("LongExitAfterXBars");
}
}
// Short --------
if(Position.MarketPosition == MarketPosition.Short) {
// Exit After X Bars
if (BarsSinceEntry("Short") >= 5-1) {
sqExitShort("ShortExitAfterXBars");
}
}
}
override protected void sqDefineStopLoss(int direction) {
stopLoss.type = CalculationMode.Ticks;
if(direction == 1) {
// long
stopLoss.value = 35;
} else {
// short
stopLoss.value = 35;
}
}
override protected void sqDefineProfitTarget(int direction) {
profitTarget.type = CalculationMode.Ticks;
if(direction == 1) {
// long
profitTarget.value = 0;
} else {
// short
profitTarget.value = 0;
}
}
#region Properties
#endregion
}
}